<script>
  import $ from 'dfish-widget'
  import Widget from '../Widget.vue'
  import src from '../widget.src.js'

  export default {
    mixins: [Widget],
    data() {
      return {
        name: 'Ajax',
        remark: 'Ajax命令',
        hasCommon: false,
        isW: false,
        extends: [src],
        attrs: [{
          name: 'data',
          remark: 'post提交的数据',
          type: 'Object / String',
        }, {
          name: 'src',
          remark: '提交数据的目标URL。其中$0,..$n变量会根据cmd()方法提供的args部分来替换',
          type: 'String',
        }, {
          name: 'loading',
          remark: '是否显示一个加载提示框',
          type: 'Boolean / Loading',
        }, {
          name: 'download',
          remark: '是否下载',
          type: 'Boolean',
        }, ],
        examples: [{
          remark: '点击"测试"按钮，调用Ajax命令。返回一个Promise',
          type: 'html',
          code: `
            <template>
              <w-view :commands="commands">
                <w-button @click="save" text="测试"></w-button>
              </w-view>
            </template>
            <${'script'}>
              import $ from 'dfish-widget'
              export default {
                data() {
                  return {
                    commands: {
                      'send': {
                        type: 'Ajax',
                        src: 'data.sp?id=$0', //此处的"$0"将被替换成"001"
                        loading: true,
                        success: (data) => {
                          console.log(data)
                        }
                      }
                    }
                  }
                },
                methods: {
                  save(e) {
                    $(e).cmd('send', '001')
                  }
                }
              }
            </${'script'}>
            `
        }]
      }
    }
  }
</script>
